<template>
    <div class="tree-hole-container">
        <ol class="tree-hole-list" v-if="!$common.isEmpty(treeHoleList)">
            <li class="tree-hole-li" v-for="(treeHole, index) in treeHoleList" :key="index">
                <div class="tree-hole-content load-fade"
                    :class="{ leftTreeHole: index % 2 === 0 && !$common.mobile(), rightTreeHole: index % 2 !== 0 || $common.mobile() }">
                    <el-avatar shape="square" class="avatar-img" :size="36" :src="treeHole.avatar"></el-avatar>
                    <div class="tree-hole-box"
                        :style="{ background: $common.tree_hole_color[index % $common.tree_hole_color.length] }">
                        <div class="box-tag" v-if="index % 2 === 0 && !$common.mobile()"
                            :style="{ 'border-color': 'transparent transparent transparent ' + $common.tree_hole_color[index % $common.tree_hole_color.length] }">
                        </div>
                        <div class="box-tag" v-if="index % 2 !== 0 || $common.mobile()"
                            :style="{ 'border-color': 'transparent ' + $common.tree_hole_color[index % $common.tree_hole_color.length] + ' transparent transparent' }">
                        </div>
                        <!--  -->
                        <div class="my-content" v-html="treeHole.content"></div>
                        <div style="display: flex;justify-content: space-between ;border-top: 1px dashed white;">
                            <div>😃 {{ treeHole.createTime }}</div>
                            <div @click="deleteTreeHole(treeHole.id)" class="tree-hole-delete">

                                <svg viewBox="0 0 1024 1024" width="18" height="18" style="vertical-align: -2px;">
                                    <path
                                        d="M921.1392 155.392h-270.592v-48.2816c0-22.7328-18.432-41.1648-41.1648-41.1648H426.3424a41.1648 41.1648 0 0 0-41.1648 41.1648v48.2816H110.6432c-14.1312 0-25.6 11.4688-25.6 25.6s11.4688 25.6 25.6 25.6h810.496c14.1312 0 25.6-11.4688 25.6-25.6s-11.4688-25.6-25.6-25.6zM170.8032 260.0448v592.8448c0 50.8928 41.2672 92.16 92.16 92.16h500.6848c50.8928 0 92.16-41.2672 92.16-92.16V260.0448H170.8032z m249.1392 462.7968c0 14.1312-11.4688 25.6-25.6 25.6s-25.6-11.4688-25.6-25.6V443.0848c0-14.1312 11.4688-25.6 25.6-25.6s25.6 11.4688 25.6 25.6v279.7568z m243.1488 0c0 14.1312-11.4688 25.6-25.6 25.6s-25.6-11.4688-25.6-25.6V443.0848c0-14.1312 11.4688-25.6 25.6-25.6s25.6 11.4688 25.6 25.6v279.7568z"
                                        fill="#FF623E"></path>
                                </svg>
                            </div>
                        </div>
                    </div>
                </div>
            </li>
        </ol>
        <div class="tree-hole-go">
            <i class="fa fa-paper-plane" @click="launch()"></i>
        </div>
        <el-dialog title="回复" :visible.sync="isreply" width="30%" :before-close="handleClose" :append-to-body="true"
            :close-on-click-modal="false" destroy-on-close center>
            <div class="tital">
                <textarea name="text" max-cols="25" rows="10" placeholder="写下你的回复..." v-model="recordMsg"></textarea>
                <div style="display: flex;justify-content: right;">
                    <button id="submit" @click="record()">回复</button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { getTreeList, addRecord, deleteRecord } from '@/api/record.js'
import {  MessageBox } from 'element-ui'
export default {
    data() {
        return {
            recordMsg: '',
            treeHoleList: [],
            isreply: false,
        }
    },

    computed: {},

    watch: {},

    created() {

    },

    mounted() {
        this.show()
    },

    methods: {
        show() {
            getTreeList().then(res => {
                this.treeHoleList = res
            })
        },
        launch() {
            this.isreply = true
        },
        handleClose() {
            this.isreply = false
            this.recordMsg = ''
        },
        deleteTreeHole(id) {
            MessageBox.confirm('确认删除吗？', '系统提示', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
            }
            ).then(() => {
                deleteRecord(id).then(res => {
                    if (res == undefined) {
                        this.$message({
                            message: '删除成功!',
                            type: "success"
                        })
                    } else {
                        this.$message({
                            message: "删除失败!",
                            type: "error"
                        })
                    }
                    this.show();
                })
            }
            ).catch(() => {
                this.$message({
                    message: '已取消删除!',
                    type: "info"
                })
            })
        },
                record() {
                if(this.recordMsg == '') {
                this.$message({
                    message: '不能为空哦!',
                    type: 'warning'
                })
                return;
            }
            addRecord(this.recordMsg).then(res => {
                if (res == undefined) {
                    this.$message({
                        message: '回复成功!',
                        type: "success"
                    })
                } else {
                    this.$message({
                        message: "回复失败!",
                        type: "error"
                    })
                }
                this.handleClose()
                this.show();
            })
        },
    }
}
</script>

<style scoped>
.tree-hole-container {
    padding: 20px;
    margin: 0 auto;
}

.tree-hole-list {
    padding: 100px 0 20px;
    margin: 0;
    position: relative;
    list-style: none;
}

.tree-hole-list:before {
    content: '';
    width: 4px;
    border-radius: 50%;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgb(255, 170, 0);
}

.tree-hole-list:after {
    content: '';
    width: 12px;
    height: 12px;
    border: 4px solid rgb(234, 98, 98);
    border-radius: 50%;
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    animation: weiYanShadowFlashing 1.5s linear infinite;
}

@keyframes weiYanShadowFlashing {
    0% {
        box-shadow: none;
    }

    50% {
        box-shadow: 0 0 15px rgb(255, 0, 0);
    }

    100% {
        box-shadow: none;
    }
}

.tree-hole-li {
    margin: 5px auto;
}

.tree-hole-content {
    position: relative;
    width: 50%;
}

.leftTreeHole {
    text-align: right;
}

.rightTreeHole {
    margin-left: 50%;
}

.tree-hole-content:before {
    content:'';
    width: 12px;
    height: 12px;
    border: 4px solid rgb(91, 228, 255);
    border-radius: 50%;
    position: absolute;
    top: 10px;
    background-color: white;
}

.leftTreeHole:before {
    right: 0;
    transform: translateX(10px);
}

.rightTreeHole:before {
    left: 0;
    transform: translateX(-10px);
}

.avatar-img {
    position: absolute;
    top: 0;
    transition: all 0.3s ease-in-out;
}

.leftTreeHole .avatar-img {
    right: 25px;
}

.rightTreeHole .avatar-img {
    left: 25px;
}

.tree-hole-box {
    font-size: 16px;
    padding: 10px;
    width: 360px;
    border-radius: 5px;
    position: relative;
    letter-spacing: 0.1em;
    font-weight: 400;
    transition: all 0.3s ease-in-out;
    color: var(--black);
    text-align: left;
    display: inline-block;
}

.leftTreeHole .tree-hole-box {
    margin-right: 90px;
}

.rightTreeHole .tree-hole-box {
    margin-left: 90px;
}

.tree-hole-box:hover,
.avatar-img:hover {
    transform: translateY(-5px);
    box-shadow: 0 0 15px 5px rgba(132, 132, 132, 0.592);
}

.box-tag {
    content: '';
    position: absolute;
    border-style: solid;
}

.leftTreeHole .box-tag {
    right: -10px;
    border-width: 15px 0 5px 10px;
}

.rightTreeHole .box-tag {
    left: -10px;
    border-width: 15px 10px 5px 0;
}

.my-content {
    margin: 0 10px 10px;
    line-height: 30px;
    font-family: 'welcomeFont'
}

.tree-hole-box>div:last-child {
    color: var(--greyFont);
    padding: 10px 10px 0;
    border-top: 1px dashed var(--white);
    font-size: 14px;
}

.tree-hole-go {
    color: var(--blue);
    font-weight: 700;
    font-size: 25px;
    margin: 20px auto;
    text-align: center;
}

.tree-hole-go i {
    cursor: pointer;
}

.tree-hole-go i:hover {
    animation: scale 1s linear infinite;
}

.tital {
    font-size: 1.5em;
    font-family: 'NavbarFont', 黑体;
    color: rgb(255, 175, 46);
    background-color: white;
}

textarea {
    width: 100%;
    height: 150px;
    border: 1px solid rgb(174, 174, 174);
    margin-top: 2vh;
    padding-top: 10px;
    border-radius: 10px;
    resize: none;
    outline: none;
    font-size: 20px;
}

textarea:focus {
    border: 1px solid rgb(255, 175, 46)
}

#submit {
    height: 30px;
    width: 60px;
    background-color: rgb(127, 88, 255);
    border: none;
    color: white;
    border-radius: 5px;
}

#submit:active {
    background-color: rgba(46, 147, 255, 0.484);
}

.tree-hole-delete {
    font-size: 14px;
    cursor: pointer;
}

@media screen and (max-width: 1000px) {
    .tree-hole-box {
        width: calc(100% - 90px);
    }
}

@media screen and (max-width: 600px) {
    .tree-hole-content {
        margin-bottom: 50px;
    }

    .tree-hole-list:after {
        left: 0;
    }

    .tree-hole-list:before {
        left: 0;
    }

    .rightTreeHole {
        margin-left: unset;
    }

    .tree-hole-content {
        width: 100%;
    }
}
</style>